import { ConversationInfoListItemType } from "../common/types/conversation";
import axios, { baseURL } from "./http";

export async function getConversationList() {
  const result = await axios.get(`${baseURL}/getConversationList`);
  return result;
}

export async function getConversationById(conversationId: number) {
  const result = await axios.post(`${baseURL}/getConversationById`, {
    conversation_id: conversationId
  });

  const { data } = result;
  const { conversation } = data;

  return conversation;
}

// user_id: user_info.id, // 发起者
// another_user_id: another_user_info.id, // 接受者
// content: curEditor.txt.text(), // 内容

interface messageData {
  user_id: number;
  another_user_id: number;
  content: string;
  content_type?: number;
}

export async function sendMessage(MessageData: messageData) {
  const result = await axios.post(`${baseURL}/postMessage`, MessageData);

  const { data } = result;
  const { conversation } = data;
  return conversation;
}

export async function getConversationInfo(currentConversationId: number) {
  const result = await axios.post(`${baseURL}/getConversationInfos`, {
    conversation_id: currentConversationId,
  });
  return result;
}

export async function getAllConversationInfosWithStaff(userId: number) {
  const result = await axios.post(`${baseURL}/getAllConversationInfosWithStaff`, {
    user_id: userId,
  });
  return result;
}

export async function endTicket(conversationId: number, staffId: number) {
  const result = await axios.post(`${baseURL}/endTicket`, {
    conversation_id: conversationId,
    staff_id: staffId
  });
  return result;
}
